package com.leftshine.dnstest.NetworkUtils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.leftshine.dnstest.BuildConfig;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class ApplicationUtil {

    public static String getAppInfo (Context context){
        String appName = null;
        String packageName = null;
        String version = null;
        String updateTime = null;
        String author = "panchenjian@goke.com";
        try {
            PackageManager packageManager = context.getPackageManager();
            ApplicationInfo applicationInfo  = packageManager.getApplicationInfo(context.getPackageName(), 0);
            PackageInfo packageInfo =packageManager.getPackageInfo(context.getPackageName(), 0);
            appName = (String)packageManager.getApplicationLabel(applicationInfo);
            packageName = applicationInfo.packageName;
            version = packageInfo.versionName;
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
            Date date= new Date(BuildConfig.TIMESTAMP);
            updateTime = format.format(date);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return appName+"-"+ packageName + "-v"+version + " by " + author + " © " + updateTime;
    }
}
